package com.project.microweatherservice.controller.publicapi;

import com.project.microweatherservice.service.LoadCityDataService;
import com.project.microweatherservice.service.WeatherReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping("/report")
public class WeatherReportApi {

    @Autowired
    private WeatherReportService weatherReportService;
    @Autowired
    private LoadCityDataService loadCityDataService;

    @RequestMapping(value = "/city/id/{cityId}", method = RequestMethod.GET)
    public ModelAndView getReportByCityId(@PathVariable Integer cityId, Model model) {
        model.addAttribute("title", "Weather Report");
        model.addAttribute("cityId", cityId);
        model.addAttribute("cityList", loadCityDataService.loadData());
        model.addAttribute("report", weatherReportService.getDataByCityId(cityId));
        return new ModelAndView("weather/report", "reportModel", model);
    }
}
